new Vue({
	el:'#app',
	data:{
		disabled:true,
		courtIds:[],     //全部法院
		mainLawyers:[] ,  //全部律师
		Case_law:{
			caseId:'',
			clientId:{
				clientId:''
			},
			oppositeId:{
				clientId:''
			},
			caseTypeid:{
				caseTypeid:''
			},
			thirdParty:'',
			objectOfAction:'',
			locusStandi:'',
			agencyMoney:'',
			blendMoney:'',
			courtId:{
				courtId:''
			},
			stateSessionDate:'',
			sessionDate:'',
			causeOfAction:'',
			causeDetails:'',
			mainLawyer:{
				empId:''
			},
			version:'',
			comment:'',
			submitId:{
				userId:''
			}
		},
		Case_audit:{
			caseid:{
				caseId:{

				}
			},
			auditid:{
				submitid:{
					userId:''
				},
				remark:''
			}
		}
	},
	created(){
		//初始化请求得到客户类型和客户状态
		this.init();
	},
	methods:{
		init(){
			//获取所有法院
			this.$http.post("http://localhost:8080/case_count/selectList",
				{emulateJSON:true}).then(result=>{
				var msg = eval("("+result.body+")")
				this.courtIds = msg.data;
			});
			//获取所有律师
			this.$http.post("http://localhost:8080/HrEmp/selectList",
				{emulateJSON:true}).then(result=>{
				var msg = eval("("+result.body+")");
				this.mainLawyers = msg.data;
			});
			//生成案件号 （当前年 +案件类型第一个字+最大version+1）
			this.$http.post("http://localhost:8080/law/getMaxKey",
				{emulateJSON:true}).then(result=>{
				var msg = eval("("+result.body+")")
				this.Case_law.version = parseInt(msg.data)+1;
				//得到年
				var date = new Date();
				var nian = date.getFullYear();
				//得到案件类型
				var typeName = (localStorage.getItem("typeName")).substring(0,1);
				this.Case_law.caseId = nian+"年"+"("+typeName+")"+"第"+this.Case_law.version+"号";
			});
		},
		onSubmit() {
			//将委托人和 对方当事人的id赋值
			this.Case_law.clientId.clientId=localStorage.getItem("clientid");
			this.Case_law.oppositeId.clientId = localStorage.getItem("oppositeld");
			//将选中的案件类型添加
			this.Case_law.caseTypeid.caseTypeid = localStorage.getItem("typeid");
			//获取reids中的用户key
			var userid =  $.cookie("redisId");
			this.Case_law.submitId.userId = userid;
			var data = JSON.stringify(this.Case_law);

			this.$http.post("http://localhost:8080/law/insertOne",
				{"data":data},{emulateJSON:true}).then(result=>{
				var msg = eval("("+result.body+")")
				if(msg.code == 0){
					this.$message.success('添加成功！~');
					this.disabled = false;
				}
			});
		},
		register(){  //进入审批流程
			//获取reids中的用户key
			var userid =  $.cookie("redisId");
			this.Case_audit.auditid.submitid.userId = userid;
			//获取提交备注
			this.Case_audit.auditid.remark = this.Case_law.comment;
			//获取案号
			this.Case_audit.caseid.caseId = this.Case_law.caseId;
			//提交到后台
			var data = JSON.stringify(this.Case_audit);

			this.$http.post("http://localhost:8080/audit/startProcess",
				{"data":data},{emulateJSON:true}).then(result=>{
				var msg = eval("("+result.body+")")
				alert(msg.data);
				//提交完成跳转到案件显示页面
				window.location.href="Case_init.html";
			});
		}
	}
});
